package {
	import com.learnosity.extendotext.ExtendoText;
	import com.learnosity.extendotext.StyleSheet;
	import com.learnosity.extendotext.tags.*;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.*;
	import flash.utils.Dictionary;

	public class TextRender extends Sprite
	{
	
		private	var ss:StyleSheet = new StyleSheet();
		private var myContent:String = 'Hello <b>Test</b> World<sup>super1 <b>Bold</b> script</sup> Hello <sub>Subscript World Hello</sub> World <img src="test.png" fred="true" /> Hello  b4audio <audio src="test.mp3" /> afterAudio   <i> World Hello</i> World <em>Hello World Hello</em> World Hello World ';
		private var extendoText:ExtendoText;
		
		public function TextRender()
		{
					
			var loader:URLLoader = new URLLoader();
	        var request:URLRequest = new URLRequest("default.css");
	        loader.addEventListener(Event.COMPLETE, completeHandler);
	        
            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }

		}

		private function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
            trace("completeHandler: " + loader.data);

			// dictionary handling class mapping
			var mapper:Dictionary = new Dictionary();
			mapper['audio'] = Audio;
			mapper['img'] = Img;
			mapper['video'] = Video;

			var startTime:int = flash.utils.getTimer();

    		ss.content = loader.data;

			extendoText = new ExtendoText(mapper,ss);
			extendoText.text = myContent;
			
			addChild ( extendoText );
			
			trace('Time taken: '+String(flash.utils.getTimer()-startTime)+'ms');
			
		}
	}
}
